/************************************************************************
 * <br>
 * <ul>
 * <li>版权所有：唐山弘川科技有限公司 2009－2020</li>
 * <li>创建日期：2009-8-4</li>
 * <li>初始作者：刘川</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 ***********************************************************************/
/*package com.hy.enterprise.framework.service.seam ;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;

import com.vsoft.libra.enterprise.framework.service.IServiceComponentInvoker;
import com.vsoft.libra.enterprise.framework.service.ServiceInvokationException;
import com.vsoft.libra.enterprise.framework.util.LibraUtil;
import com.vsoft.libra.enterprise.framework.util.converter.DefaultConverter;
import com.vsoft.libra.enterprise.framework.util.lang.ClassUtil;
import com.vsoft.libra.enterprise.framework.util.logger.SeamLoggerUtil;
import com.vsoft.libra.enterprise.framework.util.seam.SeamUtil;

*//**
 * <ul>
 * <li>设计作者：刘川</li>
 * <li>设计日期：2009-8-4</li>
 * <li>设计时间：下午12:53:25</li>
 * <li>设计目的：Seam组件调用器</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 *//*
@ Name ( "com.vsoft.libra.enterprise.framework.service.seam.SeamServiceComponentInvoker" )
@ Scope ( ScopeType.EVENT )
public class SeamServiceComponentInvoker implements IServiceComponentInvoker
{
	*//**
	 * 日志记录器
	 *//*
	private static LogProvider	logger	=
	                                      Logging
	                                             .getLogProvider ( SeamServiceComponentInvoker.class ) ;

	*//**
	 * 构造函数
	 *//*
	public SeamServiceComponentInvoker ( )
	{
		super ( ) ;
	}

	*//**
	 * @see com.vsoft.libra.enterprise.framework.service.IServiceComponentInvoker#callComponentMethod(java.lang.String,
	 *      java.lang.String, java.lang.Object[])
	 *//*
	public Object callComponentMethod (
	                                    final String targetName ,
	                                    final String methodName ,
	                                    final Object [ ] arguments )
	{
		SeamLoggerUtil
		              .debug (
		                       SeamServiceComponentInvoker.logger ,
		                       "SeamServiceComponent类callComponentMethod方法所接收到的方法参数为：\n"
		                               + "targetName ==> "
		                               + targetName
		                               + "----------"
		                               + "methodName ==> "
		                               + methodName
		                               + "----------"
		                               + "arguments ==> "
		                               + arguments ) ;
		*//**
		 * 初始化方法调用参数数组
		 *//*
		Object [ ] argumentsForInvoke =
		                                arguments ;
		*//**
		 * 所需要调用的目标Seam组件实例
		 *//*
		Object targetInstance =
		                        Expressions
		                                   .instance ( )
		                                   .createValueExpression (
		                                                            "#{"
		                                                                    + targetName
		                                                                    + "}" )
		                                   .getValue ( ) ;
		SeamLoggerUtil
		              .debug (
		                       SeamServiceComponentInvoker.logger ,
		                       "所需要调用的目标Seam组件实例为：\n"
		                               + ToStringBuilder
		                                                .reflectionToString (
		                                                                      targetInstance ,
		                                                                      ToStringStyle.MULTI_LINE_STYLE ) ) ;
		Class < ? > targetClass =
		                          SeamUtil
		                                  .getComponentType (
		                                                      targetName ,
		                                                      targetInstance ) ;
		// SeamLoggerUtil
		// .debug (
		// SeamServiceComponentInvoker.logger ,
		// "所需要调用的目标Seam组件的类型为："
		// + targetClass ) ;
		Class < ? > [ ] methodArgumentsTypes =
		                                       LibraUtil
		                                                .convertNullToObjectClass ( LibraUtil
		                                                                                     .getArgumentTypes ( arguments ) ) ;
		// SeamLoggerUtil
		// .debug (
		// SeamServiceComponentInvoker.logger ,
		// "所需要调用的目标Seam组件的参数类型列表为："
		// + methodArgumentsTypes ) ;
		Method method =
		                MethodUtils
		                           .getMatchingAccessibleMethod (
		                                                          targetClass ,
		                                                          methodName ,
		                                                          methodArgumentsTypes ) ;
		if ( method == null )
		{
			try
			{
				method =
				         ClassUtil
				                  .findMethod (
				                                targetClass ,
				                                methodName ,
				                                arguments ) ;
				// SeamLoggerUtil
				// .debug (
				// SeamServiceComponentInvoker.logger ,
				// "通过自定义ClassUtil的findMethod方所获取的方法为："
				// + method ) ;
				argumentsForInvoke =
				                     new DefaultConverter ( )
				                                             .convertForDeserialization (
				                                                                          arguments ,
				                                                                          method
				                                                                                .getGenericParameterTypes ( ) ) ;
				// SeamLoggerUtil
				// .debug (
				// SeamServiceComponentInvoker.logger ,
				// "当前，通过自定义的ClassUtil助手类所获取的方法为："
				// + method ) ;
				// SeamLoggerUtil
				// .debug (
				// SeamServiceComponentInvoker.logger ,
				// "当前，通过自定义的默认转换器所获取到的参数列表为："
				// + argumentsForInvoke ) ;
			}
			catch ( NoSuchMethodException noSuchMethodException )
			{
				SeamServiceComponentInvoker.logger
				                                  .debug ( noSuchMethodException
				                                                                .getMessage ( ) ) ;
				throw new ServiceInvokationException (
				                                       noSuchMethodException ) ;
			}
		}
		try
		{
			SeamLoggerUtil
			              .debug (
			                       SeamServiceComponentInvoker.logger ,
			                       "SeamServiceComponentInvoker.callComponentMethod()中实际执行服务方法调用的方法对象为：\n"
			                               + ToStringBuilder
			                                                .reflectionToString (
			                                                                      method ,
			                                                                      ToStringStyle.MULTI_LINE_STYLE ) ) ;
			// SeamLoggerUtil
			// .debug (
			// SeamServiceComponentInvoker.logger ,
			// "SeamServiceComponentInvoker.callComponentMethod()中实际执行服务方法调用的组件对象为："
			// + ToStringBuilder
			// .reflectionToString (
			// targetInstance ,
			// ToStringStyle.MULTI_LINE_STYLE ) ) ;
			Object object =
			                method
			                      .invoke (
			                                targetInstance ,
			                                argumentsForInvoke ) ;
			// Object object =
			// MethodUtils
			// .invokeMethod (
			// targetInstance ,
			// methodName ,
			// argumentsForInvoke ) ;
			SeamLoggerUtil
			              .debug (
			                       SeamServiceComponentInvoker.logger ,
			                       "类：["
			                               + targetInstance
			                                               .getClass ( )
			                               + "]的方法：["
			                               + method
			                                       .getName ( )
			                               + "]调用后所生成的结果为：[\n"
			                               + ToStringBuilder
			                                                .reflectionToString (
			                                                                      object ,
			                                                                      ToStringStyle.MULTI_LINE_STYLE )
			                               + "\n]" ) ;
			return object ;
		}
		catch ( IllegalAccessException illegalAccessException )
		{
			SeamLoggerUtil
			              .error (
			                       SeamServiceComponentInvoker.logger ,
			                       illegalAccessException
			                                             .getMessage ( ) ,
			                       illegalAccessException ) ;
			throw new ServiceInvokationException (
			                                       illegalAccessException ) ;
		}
		catch ( IllegalArgumentException illegalArgumentException )
		{
			SeamLoggerUtil
			              .error (
			                       SeamServiceComponentInvoker.logger ,
			                       illegalArgumentException
			                                               .getMessage ( ) ,
			                       illegalArgumentException ) ;
			throw new ServiceInvokationException (
			                                       illegalArgumentException ) ;
		}
		catch ( InvocationTargetException invocationTargetException )
		{
			SeamLoggerUtil
			              .error (
			                       SeamServiceComponentInvoker.logger ,
			                       invocationTargetException
			                                                .getMessage ( ) ,
			                       invocationTargetException ) ;
			throw new ServiceInvokationException (
			                                       invocationTargetException ) ;
		}
		// catch ( NoSuchMethodException noSuchMethodException )
		// {
		// SeamLoggerUtil
		// .error (
		// SeamServiceComponentInvoker.logger ,
		// noSuchMethodException
		// .getMessage ( ) ,
		// noSuchMethodException ) ;
		// throw new ServiceInvokationException (
		// noSuchMethodException ) ;
		// }
	}
}*/
